home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.04 Apr 95 / TreeAppƒ / Eric's C++ Libraries / Interface Classes / CPPIntText.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  2.1 KB  |  87 lines  |  [TEXT/KAHL]

  1. /********************************************************* DEFINITION
  2.     DATE:    9/28/93
  3.     AUTHOR: Eric R. Rosé
  4.     
  5.     CLASS:  CPPDialogIntText
  6.     
  7.     SUPERCLASS: CPPDialogText
  8.     
  9.         This C++ class manages a textedit area with no scrollbars and
  10.         only accepts numbers up to 255 characters.
  11.     
  12. ********************************************************************/
  13.  
  14. #include <CPPIntText.h>
  15.  
  16. /*-----------------------------------------------------------------*/
  17. /*------------------------ PUBLIC METHODS -------------------------*/
  18. /*-----------------------------------------------------------------*/
  19.  
  20.     CPPIntText::CPPIntText (CPPWindow *OurWindow,
  21.                                        Rect *itsBounds,
  22.                                        int defaultValue,
  23.                                        int maxLength,
  24.                                        int Font,
  25.                                        int FSize) :
  26.                    CPPDialogText (OurWindow, itsBounds, (StringPtr)NULL,
  27.                                      maxLength, Font, FSize)
  28.     {
  29.         SetFilterKind (number);    // only numbers are allowed
  30.         SetFilterSense (pass);
  31.         SetFilterString (NULL);
  32.         
  33.         SetToInt(defaultValue);    
  34.     }
  35.  
  36. /*-----------------------------------------------------------------*/
  37.  
  38.     CPPIntText::~CPPIntText (void)
  39.     {    
  40.     }
  41.     
  42. /*-----------------------------------------------------------------*/
  43.  
  44.     Boolean    CPPIntText::Member (char *className)
  45.     {
  46.         if (strcmp(className, CPPIntText::ClassName()) == 0)
  47.           return TRUE;
  48.         else
  49.           return CPPDialogText::Member(className);
  50.     }
  51.  
  52. /*-----------------------------------------------------------------*/
  53.  
  54.     char    *CPPIntText::ClassName (void)
  55.     {
  56.         return "CPPDialogIntText";
  57.     }
  58.  
  59. /*-----------------------------------------------------------------*/
  60.  
  61.     int    CPPIntText::GetAsInt (void)
  62.     /* Convert the contents of the TEArea into an integer and return it */
  63.     {
  64.         StringPtr    STemp = GetAsString();
  65.         long        tempLInt;
  66.         
  67.         if (STemp)
  68.           {
  69.               StringToNum(STemp, &tempLInt);
  70.               return tempLInt;
  71.           }    
  72.         else
  73.           return 0;
  74.     }
  75.     
  76.  
  77. /*-----------------------------------------------------------------*/
  78.  
  79.     void    CPPIntText::SetToInt (int newValue)
  80.     /* set the text object to contain the passed in integer value */
  81.     {
  82.         Str255    STemp;
  83.         
  84.         NumToString (newValue, STemp);
  85.         SetToString (STemp);
  86.     }
  87.